package com.zuo.demo01.config;


import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/login.html").setViewName("admin/login");
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /*registry.addInterceptor(new LoginHandlerInterceptor())
                .addPathPatterns("/admin/**");
*/
    }


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //String path1 = System.getProperty("user.dir")+"/src/main/resources/static/imgs/blogs/content/";
        //String path2 = System.getProperty("user.dir")+"/src/main/resources/static/imgs/blogs/header/";
        //String path3 = System.getProperty("user.dir")+"/src/main/resources/static/images/header/";//头像
        String path1 = "/images/blogs/content/";
        String path2 = "/images/blogs/header/";
        String path3 = "/images/header/";//头像
        //System.out.println(this.getClass().getSimpleName()+"->"+path3);
        ///imgs/blogs/content/**是对应resource下工程目录
        registry.addResourceHandler("/images/blogs/content/**").addResourceLocations("file:"+path1);
        registry.addResourceHandler("/images/blogs/header/**").addResourceLocations("file:"+path2);
        registry.addResourceHandler("/images/header/**").addResourceLocations("file:"+path3);//头像
    }


}
